/*
 * initialization has been moved to form_controls_init
 */
/*Event.observe(window, 'load', function(e){
	$$('textarea.rte').each( function(t){
		initializeFCKEditor(t);
	});
});*/

function initializeFCKEditor(t){
	if( t.readAttribute('id')){
		var id = t.readAttribute('id');
		var config = t.readAttribute('rte_config');
		var toolbar = t.readAttribute('rte_toolbar');
		var dims = getDimensionsOfHiddenItem(t);
		var fck = new FCKeditor(id, dims.width, dims.height);
		fck.BasePath = ApplicationPaths.basepath + '/js/fckeditor/';
		fck.ToolbarSet = toolbar || 'Basic';
		if( config ){
			fck.Config["CustomConfigurationsPath"] = fck.BasePath + config + ".js" 
		}
		fck.ReplaceTextarea();
	}
}

function getDimensionsOfHiddenItem(t){
	var dims = {
		width: null,
		height: null
	}
	t = $(t);
	if( t ){
		var parents = [];
		var temp = $(t.parentNode);
		while( temp && temp.tagName != 'BODY'){
			if( !temp.visible() ){
				parents.push({
					'elm': temp,
					'display': temp.getStyle('display')
				});
				temp.show();
			}
			temp = $(temp.parentNode);
		}
		var d = t.getStyle('display');
		t.show();
		dims = t.getDimensions();
		t.setStyle({'display': d});
		parents.each( function(e){
			e.elm.setStyle({
				'display': e.display
			});
		});
	}
	return dims;
}
